﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using GIMS.Def.Arguments;

namespace GIMS.GUI.ArgumentControls
{
    public class DrawArgumentControlViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public DrawArgumentControlViewModel(DrawArgument drawArgument)
        {
            DrawArgument = drawArgument;
            DrawArgument.PropertyChanged += new PropertyChangedEventHandler(DrawArgument_PropertyChanged);
            InitShapeValues();
        }

        public DrawArgument DrawArgument { get; private set; }


        public bool IsText
        {
            get { return DrawArgument.Shape == Shape.text; }
        }

        public bool IsNotText
        {
            get { return DrawArgument.Shape != Shape.text; }
        }

        public IEnumerable<ShapeRepresenter> ShapeRepresenters
        {
            get;
            private set;
        }

        private void DrawArgument_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "SelectedShape")
            {
                OnPropertyChanged("IsText");
                OnPropertyChanged("IsNotText");
            }
        }

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void InitShapeValues()
        {
            var shapeValues = new List<ShapeRepresenter>();
            var values = Enum.GetValues(typeof(Shape));

            foreach (var value in values)
            {
                var shapeValue = new ShapeRepresenter { Name = Enum.GetName(typeof(Shape), value), Value = (Shape)value };
                shapeValues.Add(shapeValue);
            }

            ShapeRepresenters = shapeValues;
        }
    }
}
